package com.example.l2048;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //获取手机屏幕像素
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
        gameCanvasWidth = metrics.widthPixels;

        //计算游戏画布的宽度（95%）
        gameCanvasWidth = (int)(gameCanvasWidth * 0.95);

        //获取根控件
        ly_Root = findViewById(R.id.ly_Root);
        //创建fl_gameCanvas控件
        flGameCanvas = new GameCanvas(this, gameCanvasWidth,
                (TextView) findViewById(R.id.cur_score),
                (TextView)findViewById(R.id.max_score),
                (TextView)findViewById(R.id.tv_2048),
                getSharedPreferences("file_max_score",MODE_PRIVATE));
        ly_Root.addView(flGameCanvas);
    }

    //private
    private LinearLayout ly_Root;
    private GameCanvas flGameCanvas;
    private int gameCanvasWidth;
}